function addToFavorites(title, url) {

	if (window.sidebar) { // Mozilla
			window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE
		window.external.AddFavorite( url, title);
	}
	
}

/**
 * Get specific cookie value by key
 * @return null | string
 */
function getCookie(key) {
   var c_pairs = document.cookie.split(';');
   var c_data  = [];
   for(var i=0; i<c_pairs.length; i++) {
	   var pair = c_pairs[i].split('=');
	   c_data[$.trim(pair[0])] = pair[1];
   }

   var c_target_v;
   if (c_data[key] != undefined) {
      c_target_v = c_data[key];
   } else {
      var pair = document.cookie.split('=');
      if (pair.length > 0) {
         c_target_v = pair[1];
      } else {
         c_target_v = null;
         alert(c_target_v);
      }
   }

   return c_target_v == null ? null : decodeURIComponent(c_target_v);
}

/**
 * Set cookie
 */
function setCookie(name, value) {
	var argv    = setCookie.arguments;
	var argc    = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path    = (argc > 3) ? argv[3] : null;
	var domain  = (argc > 4) ? argv[4] : null;
	var secure  = (argc > 5) ? argv[5] : false;

	document.cookie = name + "=" + encodeURIComponent(value) +
					  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
                      ((path == null)    ? "" : ("; path=" + path)) +
                      ((domain == null)  ? "" : ("; domain=" + domain)) +
                      ((secure == true)  ? "; secure" : "");
}

/**
 * Set cookies
 * @param string c_key cookies key
 * @param string c_value cookies value
 */
function executeCookie(c_key, c_value) {
    var myDomain = '/';
    var largeExpDate = new Date ();
    largeExpDate.setTime(largeExpDate.getTime() + (7 * 24 * 3600 * 1000));
    setCookie(c_key, c_value, largeExpDate, myDomain);
}


function search_tabs_switcher() {
    var tab_active = getCookie('main_tab');

    if (tab_active == 'hotels') {
       $('#search_tab_hotels').attr('class', 'search_tab_hotels_on');
       $('#search_tab_holidays').attr('class', 'search_tab_holidays_off');
       $('#search_type_hotels').attr('checked', 'checked');
       $('#search_type_holidays').removeAttr('checked');
       $('#form_package').hide();
       $('#form_hotel').show();
    } else if (tab_active == 'holidays') {
       $('#search_tab_holidays').attr('class', 'search_tab_holidays_on');
       $('#search_tab_hotels').attr('class', 'search_tab_hotels_off');
       $('#search_type_holidays').attr('checked', 'checked');
       $('#search_type_hotels').removeAttr('checked');
       $('#form_hotel').hide();
       $('#form_package').show();
    }

}

$(function(){
    //Reads cookie and shows active tab at page loading
    search_tabs_switcher();

    //Search tab click  - hotels/holidays
	$('.box_search_tabs :input[name=search_type]').click(function(e){
        var tab_type = e.target.id;
        var tab_active = getCookie('main_tab');
		try {
			if (tab_type == 'search_type_hotels') {
                tab_active != 'hotels' ? executeCookie('main_tab', 'hotels') : false;
                search_tabs_switcher();
			} else {
                tab_active != 'holidays' ? executeCookie('main_tab', 'holidays') : false;
                search_tabs_switcher();
			}
		} catch(e) {
		}
	});

    //Datepickers set up
    try {
        //hotels picker
		var hotels_day = $('#hotels-date-day').val();
		var hotels_my = $('#hotels-date-month').val();
        var m_y_pair = hotels_my.split('-');
        var hotels_month = m_y_pair[0];
        var hotels_year = m_y_pair[1];
	    $("#datepicker-hotels").val(hotels_day + '.' + hotels_month + '.' + hotels_year);

        //holidays
  		var holidays_day = $('#holidays-date-day').val();
		var holidays_my = $('#holidays-date-month').val();
        var m_y_pair = holidays_my.split('-');
        var holidays_month = m_y_pair[0];
        var holidays_year = m_y_pair[1];
	    $("#datepicker-holidays").val(holidays_day + '.' + holidays_month + '.' + holidays_year);
	}catch(e){}

    function mindate(id_el_day, id_el_my) {
		var day_el = $('#' + id_el_day).get(0);
		var my_el  = $('#' + id_el_my).get(0);

        try {
            var day = day_el.options[0].value;
            var my  = my_el.options[0].value;

            var m_y_pair = my.split('-');
            var month    = m_y_pair[0] - 1;
            var year     = m_y_pair[1];
        } catch(e) {};

        return {d:day, m:month, y:year};
    }

    function maxdate(id_el_day, id_el_my) {
		var day_el = $('#' + id_el_day).get(0);
		var my_el  = $('#' + id_el_my).get(0);

        try {
            var day = day_el.options[day_el.options.length-1].value;
            var my  = my_el.options[my_el.options.length-1].value;

            var m_y_pair = my.split('-');
            var month    = m_y_pair[0] - 1;
            var year     = m_y_pair[1];
        } catch(e){};
        return {d:day, m:month, y:year};
    }

    function pickerValueSetter(picker) {
        var day = $("#" + picker + "-date-day").val();
        var my = $("#" + picker + "-date-month").val();
        var m_y_pair = my.split('-');
        var month    = m_y_pair[0];
        var year     = m_y_pair[1];

        $("#datepicker-" + picker).val(day + '.' + month + '.' + year);
    }

    var min_hot_date =  mindate('hotels-date-day', 'hotels-date-month');
    var max_hot_date =  maxdate('hotels-date-day', 'hotels-date-month');
    var min_hol_date =  mindate('holidays-date-day', 'holidays-date-month');
    var max_hol_date =  maxdate('holidays-date-day', 'holidays-date-month');

	$("#datepicker-hotels").datepicker({
		showOn: 'button',
		buttonImage: '/images/icon_calendar.gif',
		buttonImageOnly: true,
		buttonText: 'Calendar', //'alt' and 'title' attributes
		defaultDate: new Date(hotels_year, hotels_month, hotels_day),
		minDate: new Date(min_hot_date.y, min_hot_date.m, min_hot_date.d),
		maxDate: new Date(max_hot_date.y, max_hot_date.m, max_hot_date.d),
		dateFormat: 'dd.mm.yy',

		onSelect: function(dateText) {
			var d =	dateText.split('.');
            try {
    			$('#hotels-date-day').children('[value=' + d[0] + ']').attr('selected', 'selected');
        		$('#hotels-date-month').children('[value=' + d[1] + '-' + d[2] + ']').attr('selected', 'selected');
            } catch (e) {
            }
		},

		//updates calendar 'start' date
		beforeShow: function(input) {
			var d =	input.value.split('.');
            try {
                $("#datepicker-hotels").datepicker('setDate', new Date(d[2], d[1]-1, d[0]));
            } catch (e) {
            }
		}
	});

    $('#hotels-date-day, #hotels-date-month').change(function(e){
        pickerValueSetter('hotels');
	});

        //holidays picker

	$("#datepicker-holidays").datepicker({
		showOn: 'button',
		buttonImage: '/images/icon_calendar.gif',
		buttonImageOnly: true,
		buttonText: 'Calendar', //'alt' and 'title' attributes
		defaultDate: new Date(holidays_year, holidays_month, holidays_day),
		minDate: new Date(min_hol_date.y, min_hol_date.m,  min_hol_date.d),
		maxDate: new Date(max_hol_date.y, max_hol_date.m,  max_hol_date.d),
		dateFormat: 'dd.mm.yy',

		onSelect: function(dateText) {
			var d =	dateText.split('.');
            try {
    			$('#holidays-date-day').children('[value=' + d[0] + ']').attr('selected', 'selected');
        		$('#holidays-date-month').children('[value=' + d[1] + '-' + d[2] + ']').attr('selected', 'selected');
            } catch (e) {
            }
		},

		//updates calendar 'start' date
		beforeShow: function(input) {
			var d =	input.value.split('.');
            try {
                $("#datepicker-holidays").datepicker('setDate', new Date(d[2], d[1]-1, d[0]));
            } catch (e) {
            }
		}
	});
    $('#holidays-date-day, #holidays-date-month').change(function(e){
        pickerValueSetter('holidays');
	});

});



$(document).ready( function() {
	$("#booking_details").validate({
                errorClass:"1",
		rules:{
                    
                    //All adults
                        lead_first_name_room_1_adults_1:{required: true}, 
                        lead_last_name_room_1_adults_1:{required: true},                        
                        lead_first_name_room_1_adults_2:{required: true}, 
                        lead_last_name_room_1_adults_2:{required: true},                        
                        lead_first_name_room_1_adults_3:{required: true}, 
                        lead_last_name_room_1_adults_3:{required: true},                        
                        lead_first_name_room_1_adults_4:{required: true}, 
                        lead_last_name_room_1_adults_4:{required: true},
                        
                        lead_first_name_room_2_adults_1:{required: true}, 
                        lead_last_name_room_2_adults_1:{required: true},
                        lead_first_name_room_2_adults_2:{required: true}, 
                        lead_last_name_room_2_adults_2:{required: true},                        
                        lead_first_name_room_2_adults_3:{required: true}, 
                        lead_last_name_room_2_adults_3:{required: true},
                        lead_first_name_room_2_adults_4:{required: true}, 
                        lead_last_name_room_2_adults_4:{required: true},                                                
                        
                        
                        lead_first_name_room_3_adults_1:{required: true}, 
                        lead_last_name_room_3_adults_1:{required: true},                        
                        lead_first_name_room_3_adults_2:{required: true}, 
                        lead_last_name_room_3_adults_2:{required: true},                        
                        lead_first_name_room_3_adults_3:{required: true}, 
                        lead_last_name_room_3_adults_3:{required: true},                        
                        lead_first_name_room_3_adults_4:{required: true}, 
                        lead_last_name_room_3_adults_4:{required: true},
                        
                        lead_first_name_room_4_adults_1:{required: true}, 
                        lead_last_name_room_4_adults_1:{required: true},
                        lead_first_name_room_4_adults_2:{required: true}, 
                        lead_last_name_room_4_adults_2:{required: true},                        
                        lead_first_name_room_4_adults_3:{required: true}, 
                        lead_last_name_room_4_adults_3:{required: true},
                        lead_first_name_room_4_adults_4:{required: true}, 
                        lead_last_name_room_4_adults_4:{required: true},                                                                        
                        
                      
                      //All children
                      
                        lead_last_name_room_1_children_1:{required: true}, 
                        lead_first_name_room_1_children_1:{required: true}, 
                        lead_last_name_room_1_children_2:{required: true}, 
                        lead_first_name_room_1_children_2:{required: true},                         
                        lead_last_name_room_1_children_3:{required: true}, 
                        lead_first_name_room_1_children_3:{required: true}, 
                        lead_last_name_room_1_children_4:{required: true}, 
                        lead_first_name_room_1_children_4:{required: true},                         

                        lead_last_name_room_2_children_1:{required: true}, 
                        lead_first_name_room_2_children_1:{required: true}, 
                        lead_last_name_room_2_children_2:{required: true}, 
                        lead_first_name_room_2_children_2:{required: true},                         
                        lead_last_name_room_2_children_3:{required: true}, 
                        lead_first_name_room_2_children_3:{required: true}, 
                        lead_last_name_room_2_children_4:{required: true}, 
                        lead_first_name_room_2_children_4:{required: true},                         
                        
                        lead_last_name_room_3_children_1:{required: true}, 
                        lead_first_name_room_3_children_1:{required: true}, 
                        lead_last_name_room_3_children_2:{required: true}, 
                        lead_first_name_room_3_children_2:{required: true},                         
                        lead_last_name_room_3_children_3:{required: true}, 
                        lead_first_name_room_3_children_3:{required: true}, 
                        lead_last_name_room_3_children_4:{required: true}, 
                        lead_first_name_room_3_children_4:{required: true},                         

                        lead_last_name_room_4_children_1:{required: true}, 
                        lead_first_name_room_4_children_1:{required: true}, 
                        lead_last_name_room_4_children_2:{required: true}, 
                        lead_first_name_room_4_children_2:{required: true},                         
                        lead_last_name_room_4_children_3:{required: true}, 
                        lead_first_name_room_4_children_3:{required: true}, 
                        lead_last_name_room_4_children_4:{required: true}, 
                        lead_first_name_room_4_children_4:{required: true},                         


			lead_epost1:{required: true, email: true},
			lead_epost2:{required: true,  email: true, equalTo: '#lead_epost1'},
                        lead_telephone:{required: true}
		},
		messages:{

                        lead_first_name_room_1_adults_1:{required: "Please enter the First Name of the Lead Guest"}, 
                        lead_last_name_room_1_adults_1:{required: "Please enter the last name of th Lead Guest"},                        
                        lead_first_name_room_1_adults_2:{required: "Please enter the First Name of Guest 2"}, 
                        lead_last_name_room_1_adults_2:{required: "Please enter the Last Name of Guest 2"},                        
                        lead_first_name_room_1_adults_3:{required: "Please enter the First Name of Guest 3"}, 
                        lead_last_name_room_1_adults_3:{required: "Please enter the Last Name of Guest 3 "},                        
                        lead_first_name_room_1_adults_4:{required: "Please enter the First Name of Guest 4"}, 
                        lead_last_name_room_1_adults_4:{required: "Please enter the Last Name of Guest 4"},


                        lead_first_name_room_2_adults_1:{required: "Please enter the First Name of Guest 1"}, 
                        lead_last_name_room_2_adults_1:{required: "Please enter the Last Name of Guest 1"},                       
                        lead_first_name_room_2_adults_2:{required: "Please enter the First Name of Guest 2"}, 
                        lead_last_name_room_2_adults_2:{required: "Please enter the Last Name of Guest 2"},                        
                        lead_first_name_room_2_adults_3:{required: "Please enter the First Name of Guest 3"}, 
                        lead_last_name_room_2_adults_3:{required: "Please enter the Last Name of Guest 3 "},                        
                        lead_first_name_room_2_adults_4:{required: "Please enter the First Name of Guest 4"}, 
                        lead_last_name_room_2_adults_4:{required: "Please enter the Last Name of Guest 4"},
                        
                        lead_first_name_room_3_adults_1:{required: "Please enter the First Name of Guest 1"}, 
                        lead_last_name_room_3_adults_1:{required: "Please enter the Last Name of Guest 1"},                       
                        lead_first_name_room_3_adults_2:{required: "Please enter the First Name of Guest 2"}, 
                        lead_last_name_room_3_adults_2:{required: "Please enter the Last Name of Guest 2"},                        
                        lead_first_name_room_3_adults_3:{required: "Please enter the First Name of Guest 3"}, 
                        lead_last_name_room_3_adults_3:{required: "Please enter the Last Name of Guest 3 "},                        
                        lead_first_name_room_3_adults_4:{required: "Please enter the First Name of Guest 4"}, 
                        lead_last_name_room_3_adults_4:{required: "Please enter the Last Name of Guest 4"},
                        
                        lead_first_name_room_4_adults_1:{required: "Please enter the First Name of Guest 1"}, 
                        lead_last_name_room_4_adults_1:{required: "Please enter the Last Name of Guest 1"},                      
                        lead_first_name_room_4_adults_2:{required: "Please enter the First Name of Guest 2"}, 
                        lead_last_name_room_4_adults_2:{required: "Please enter the Last Name of Guest 2"},                        
                        lead_first_name_room_4_adults_3:{required: "Please enter the First Name of Guest 3"}, 
                        lead_last_name_room_4_adults_3:{required: "Please enter the Last Name of Guest 3 "},                        
                        lead_first_name_room_4_adults_4:{required: "Please enter the First Name of Guest 4"}, 
                        lead_last_name_room_4_adults_4:{required: "Please enter the Last Name of Guest 4"},        
                        
                        lead_last_name_room_1_children_1:{required: "Please enter the Last Name of Child 1"}, 
                        lead_first_name_room_1_children_1:{required: "Please enter the First Name of Child 1"}, 
                        lead_last_name_room_1_children_2:{required: "Please enter the Last Name of Child 2"}, 
                        lead_first_name_room_1_children_2:{required: "Please enter the First Name of Child 2"},                         
                        lead_last_name_room_1_children_3:{required: "Please enter the Last Name of Child 3"}, 
                        lead_first_name_room_1_children_3:{required: "Please enter the First Name of Child 3"}, 
                        lead_last_name_room_1_children_4:{required: "Please enter the Last Name of Child 4"}, 
                        lead_first_name_room_1_children_4:{required: "Please enter the First Name of Child 4"},                         

                        lead_last_name_room_2_children_1:{required: "Please enter the Last Name of Child 1"}, 
                        lead_first_name_room_2_children_1:{required: "Please enter the First Name of Child 1"}, 
                        lead_last_name_room_2_children_2:{required: "Please enter the Last Name of Child 2"}, 
                        lead_first_name_room_2_children_2:{required: "Please enter the First Name of Child 2"},                         
                        lead_last_name_room_2_children_3:{required: "Please enter the Last Name of Child 3"}, 
                        lead_first_name_room_2_children_3:{required: "Please enter the First Name of Child 3"}, 
                        lead_last_name_room_2_children_4:{required: "Please enter the Last Name of Child 4"}, 
                        lead_first_name_room_2_children_4:{required: "Please enter the First Name of Child 4"},                         
                        
                        lead_last_name_room_3_children_1:{required: "Please enter the Last Name of Child 1"}, 
                        lead_first_name_room_3_children_1:{required: "Please enter the First Name of Child 1"}, 
                        lead_last_name_room_3_children_2:{required: "Please enter the Last Name of Child 2"}, 
                        lead_first_name_room_3_children_2:{required: "Please enter the First Name of Child 2"},                         
                        lead_last_name_room_3_children_3:{required: "Please enter the Last Name of Child 3"}, 
                        lead_first_name_room_3_children_3:{required: "Please enter the First Name of Child 3"}, 
                        lead_last_name_room_3_children_4:{required: "Please enter the Last Name of Child 4"}, 
                        lead_first_name_room_3_children_4:{required: "Please enter the First Name of Child 4"},                         

                        lead_last_name_room_4_children_1:{required: "Please enter the Last Name of Child 1"}, 
                        lead_first_name_room_4_children_1:{required: "Please enter the First Name of Child 1"}, 
                        lead_last_name_room_4_children_2:{required: "Please enter the Last Name of Child 2"}, 
                        lead_first_name_room_4_children_2:{required: "Please enter the First Name of Child 2"},                         
                        lead_last_name_room_4_children_3:{required: "Please enter the Last Name of Child 3"}, 
                        lead_first_name_room_4_children_3:{required: "Please enter the First Name of Child 3"}, 
                        lead_last_name_room_4_children_4:{required: "Please enter the Last Name of Child 4"}, 
                        lead_first_name_room_4_children_4:{required: "Please enter the First Name of Child 4"},                         

   

			lead_first_name:{required: "Please enter your name"},
			lead_last_name:{required: "Please enter your Last Name"},
			lead_epost1:{required: "Please enter the Email Address of Lead Guest",email: "Please enter a valid Email Address"},
			lead_epost2 :{required: "Please re-enter the Email Address of Lead Guest", email: "Please enter a valid Email Address",
                                      equalTo: "Please enter the same Email Addresses"},
                        lead_telephone:{required: "Please enter a Telephone Number"}                                                                   
		},
                errorContainer: "#errorList",
                errorLabelContainer: "#errorList",
                errorElement: "li",
                
                
                highlight: function(element, errorClass) {
                      $(element).css('border', '1px red solid') ;

                },
                unhighlight: function(element, errorClass) {
                    $(element).css('border', '') ;
                }
	});
});



$(document).ready( function() {
	$("#booking_payment").validate({
		errorClass: "af",
		rules:{
			cc_holder_name:{
				required: true
			},
			cc_type:{
				required: true
			},
			cc_number:{
				required: true,
                                creditcard: true
			},
			cc_security_code:{
				required: true,
                                number: true,
                                maxlength: 3
			},
			cc_address1:{
				required: true
			},
			cc_city:{
				required: true
			},
			billing_county:{
				required: true
			},
                        card_expiry_month:{
                            required: true
                        },
                        card_expiry_year:{
                            required: true
                        },
                        billing_county:{
                            required: true
                        },
                        subscribe:{
                            required: true
                        }                        
		},
		messages:{
			cc_holder_name:{required: "Please enter the Name of the Card Holder"},
			cc_type:{required: "Please select the Type of Card"},
			cc_number:{
				required: "Please enter your Card Number",
                                creditcard: "Please enter a valid Card Number"
				
			},
			cc_security_code :{
				required: "Please enter the Last 3 Digits of the card\'s security code (CVV)",
                                maxlength: "Please enter the Last 3 Digits of the card\'s security code (CVV)",
                                number: "Please enter the Last 3 Digits of the card\'s security code (CVV)"
			},
			cc_address1:{
				required: "Please enter the Card Holders Address"
				
			},
			cc_city :{
				required: "Please enter the Town"
			},                                       
                        /*cc_country_code:{
				required: "Please enter the Country"
			},*/
                        card_expiry_month: {
                              required: "Please select the Month of Expiration"
                        },
                        card_expiry_year:{
                              required: "Please select the Year of Expiration"
                        },
                        billing_county: {
                            required: "Please select the County"
                        },
                        subscribe: {
                            required: "Please agree to our Hotel Booking Terms and Conditions"
                        }                        
                        
		},
                errorContainer: "#errorList",
                errorLabelContainer: "#errorList",
                errorElement: "li",
                   highlight: function(element, errorClass) {
                       $(element).css('border', '1px red solid') ;
                   },
                   unhighlight: function(element, errorClass) {
                       $(element).css('border', '') ;
                   }
                   
	});
});

        $(document).ready(function(){
                $('#surcharge').hide();
                $('#total_credit_card').hide();  
                if ($("#special_requirements").val()){
                    $("#special_requirements").css('display', 'block');
                    $("#special_request_toggle_img").rotate(90);
                }                          

        });

        $(function() {
            $('#cc_type').change(function() {
                  if ($('#cc_type').val() == 'visa' || $('#cc_type').val() == 'mc'){
                    $('#surcharge').show();                 
                    $('#total_credit_card').show();   
                    $('#total_without_surcharge').hide();                         
                  }else{
                    $('#surcharge').hide();                 
                    $('#total_credit_card').hide();                   
                    $('#total_without_surcharge').show();                          
                  }                     
            });

        });   
        
        
        $(function(){
            $('#special_request_toggle_img').click(function () {
                  $("#special_requirements").slideToggle("fast", function(){
                      if ($(".special_request_toggle").css("display") == "none"){
                         $("#special_request_toggle_img").rotate(0);
                      }else $("#special_request_toggle_img").rotate(90);
                  });
                  
                  
             });    
            
        })
        
        
        
$(function(){
    //FansyBox elements
    var fancyOptions = {frameWidth:500, padding:0};
    var fancyFrameOptions = {type:'iframe', maxWidth:600, maxHeight:600, padding:10};

    $("a.fancy").fancybox(fancyOptions);
    $("a.frame").fancybox(fancyFrameOptions);

    //Main thumb click
    $('#main-thumb-ref').click(function(){
        $('#tab-photos').click();

        return false;
    });

    //Write review click
    $('#write-review').click(function(){
        $('#tab-reviews').click();

        return false;
    });

    //Simple tabs
    function isTab(el_id) {
        var v = el_id.split('-');
        try {
            if (v[0] == 'tab') {
                var c = $('#tab-' + v[1] + '-content').get(0);
                //first time only
                var a = $('#simple-tabs').children('li').filter(':first').children('a').get(0);
                var firstv = a.id.split('-');
                if (!isTab.inittab_in_container) {
                   isTab.inittab_in_container = true;
                   $('#tab-' + firstv[1] + '-content').html($('#simple-tabs-body').html());
                }
                return c != null;
            } else {
                return false;
            }
        } catch(e) {}
    }
    isTab.inittab_in_container = false;

    $('#simple-tabs a').click(function(e){
        is_tab = isTab(e.target.id);
        if (is_tab != true) {
            return true;
        }

        //Disactivate all tabs
        $('#simple-tabs').children('li').each(function() {
            try {
                var cl = $(this).attr('class');
                var cl_words = cl.split('_');
                $(this).attr('class', cl_words[0] + '_' + cl_words[1] +  '_' +  cl_words[2] + '_off');
                var link = $(this).children('a[id^=tab]').get(0);
                $(link).removeAttr('class');
            }catch(e){
                alert(e.message);
            }
        });

        //Activate only clicked tab
        $(e.target).attr('class', 'hotel_tab_active');
        var tab_li_class = $(e.target).closest('li').attr('class');
        var li = tab_li_class.split('_');
        $(e.target).closest('li').attr('class', li[0] + '_' + li[1] +  '_' +  li[2] + '_on');

        //Set content
        var container = e.target.id + '-content';
        $('#simple-tabs-body').html($('#' + container).html());

        //activate fansybox
        $("a.fancy").fancybox(fancyOptions);
        $("a.frame").fancybox(fancyFrameOptions);

        return false;
    });


});        


$(function(){
    $('#no_rooms').change(function(e){
        var v = $(e.target).val();
        setRooms(v); 
      //  enableChildAge();
    });

});


$(document).ready(function(){	
         setRooms($('#no_rooms').val());
         unsetRoons();
         enableAllChildAge();
});

function setRooms(v){
            try {
            switch(v) {
                case '1':
                   $('div[id^=room-]').css({'display':'none'});
                   $('#room-1').css({'display':'block'});
                break;
                case '2':
                    $('div[id^=room-]').css({'display':'none'});
                    $('#room-1, #room-2').css({display:'block'});
                break;
                case '3':
                    $('div[id^=room-]').css({'display':'none'});
                    $('#room-1, #room-2, #room-3').css({'display':'block'});
                break;
                case '4':
                    $('div[id^=room-]').css({'display':'none'});
                    $('#room-1, #room-2, #room-3, #room-4').css({'display':'block'});
                break;
                case '5':
                    $('div[id^=room-]').css({'display':'none'});
                    $('#room-1, #room-2, #room-3, #room-4, #room-5').css({'display':'block'});
                break;
            }
        } catch(v) {}
}

function enableBookBotton(hotel_id, count){

   var control = 0;
   for (var i = 1; i <= count; i++){
          if( $('input[name=room_id_' + i +']:checked', '#hotel_book_id_' + hotel_id).val() == null  ) {
           control++;
       }
   }
   
   if (control == 0){
       $('#hotel_book_' + hotel_id).prop('disabled', false);
   } else {
       $('#hotel_book_' + hotel_id).prop('disabled', true); 
   }
   
      var formIds = [];
     // to get all forms
     $("form").each(function() {
          formIds.push(this.id);
     });
     // to call method to unchecked all radions from another forms
     var formId = 0;  
     for (var k = 0; i < formIds.length; k++){
         formId = formIds[k];
         formId = formId.substr(14);         
         if (formId != hotel_id){
             $('input[name=room_id_1]:checked', '#hotel_book_id_' + formId).prop('checked', false);
             $('input[name=room_id_2]:checked', '#hotel_book_id_' + formId).prop('checked', false);
             $('input[name=room_id_3]:checked', '#hotel_book_id_' + formId).prop('checked', false);
             $('#hotel_book_' + formId).prop('disabled', true); 
         }
     }   
   
     
  

}

function unsetRoons(){
    $('input[name=room_id_1]:checked').prop('checked', false);
    $('input[name=room_id_2]:checked').prop('checked', false);
    $('input[name=room_id_3]:checked').prop('checked', false);


}

function enableAgeByRoomAndChild(room, index, display){
    var name = '#' + room + index + '_div';
    $(name).css({'display': display});
    
}

function enable(div, indexValue){
      var name = 'div[id^=' + div + ']';
      $(name).css({'display':'none'});  
      var numChildren = 4;
      for (var i = 1; i <= numChildren; i++){
          if (i <= indexValue)
            enableAgeByRoomAndChild(div, i, 'block');
      }
}

//room 1

$(function(){
    $('#room_children_1').change(function(e){
        var v = $(e.target).val();
        if (v == 0){
            $('div[id^=room_children_1_age_]').css({'display':'none'});  
        }         
          else enable('room_children_1_age_', v);
    });

});

// room 2

$(function(){
    $('#room_children_2').change(function(e){
        var v = $(e.target).val();
        if (v == 0){
            $('div[id^=room_children_2_age_]').css({'display':'none'});  
        }         
          else enable('room_children_2_age_', v);
    });

});

// room 3
$(function(){
    $('#room_children_3').change(function(e){
        var v = $(e.target).val();
        if (v == 0){
            $('div[id^=room_children_3_age_]').css({'display':'none'});  
        }         
          else enable('room_children_3_age_', v);
    });

});



function enableAllChildAge(){
    var no_rooms = 3;
    for(var i = 1; i<= no_rooms; i++){
        var name_div = 'room_children_' + i + '_age_';
        var name_select = 'room_children_' + i;
        $(name_div).css({'display':'none'});              
        var no_children = $('#' + name_select).val();
        if (no_children == 0){
            $('div[id^='+ name_div +']').css({'display':'none'});  
        } else enable(name_div, no_children);
    }    
}


$(function(){

    $(".submit").click(function(){
        var form = $(this).parents('form:first');
        $(form).submit();
    });

});